package gold.digger;

import gold.utils.InputUtil;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC950 {
    public long startExecuteTime = System.currentTimeMillis();


    /*
     * @param 此题目参考了别人代码
     * 不是因为复杂，而是因为经典
     * 未来需要再次复习此道题目
     * 有意思的题目，模拟+直接存下标，够意思
     * @return:
     */
    class Solution {
        public int[] deckRevealedIncreasing(int[] deck) {
            Arrays.sort(deck);
            Queue<Integer> queue = new LinkedList<>();
            for (int i = 0; i < deck.length; i++) {
                queue.offer(i);
            }

            int[] ans = new int[deck.length];
            for (int card : deck) {
                ans[queue.poll()] = card;
                if (!queue.isEmpty()) {
                    queue.offer(queue.poll());
                }
            }
            return ans;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(Arrays.toString(solution.deckRevealedIncreasing(InputUtil.toIntegerArray("[17,13,11,2,3,5,7]"))));
    }

    public static void main(String[] args) throws Exception {
        LC950 an = new LC950();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
